# -*- coding: utf-8 -*-

from sqlalchemy.dialects import mysql

from wxgame import db
from . import ts_func


class Statistics(db.Model):
    __tablename__ = 'statistics'

    id = db.Column(db.Integer, primary_key=True)
    wager_amount = db.Column(db.Integer, default=0)
    earned_amount = db.Column(db.Integer, default=0)
    up_point = db.Column(db.Integer, default=0)
    down_point = db.Column(db.Integer, default=0)
    # down_point = db.Column(db.Integer, default=0)
    total_point = db.Column(db.Integer, default=0)
    deduction = db.Column(db.Integer, default=0)
    envelope_count = db.Column(db.Integer, default=0)
    envelope_amount = db.Column(db.Integer, default=0)
    gameset_count = db.Column(db.Integer, default=0)
    status = db.Column(db.Integer, nullable=False, default=1)
    create_time = db.Column(db.Integer, nullable=False, default=ts_func)

    @classmethod
    def get_instance(cls):
        stat = db.session.query(cls).filter(cls.status == 1).first()
        if stat is None:
            stat = cls()
            db.session.add(stat)
            db.session.commit()
        return stat
